<!-- rights component -->
<template>
  <div class="rights-container">
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home'}">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图 -->
    <el-card class="box-card">
      <!-- 权限列表表格 -->
      <div class="user-table">
        <el-table :data="authorityList" border stripe style="width: 100%">
          <el-table-column type="index" width="50"></el-table-column>
          <el-table-column prop="authName" label="权限名称"></el-table-column>
          <el-table-column prop="path" label="路径"></el-table-column>
          <el-table-column label="使用等级">
            <template slot-scope="scope">
              <el-tag
                size="mini"
                :type="displayLev(scope.row.level, 'type')"
                v-text="displayLev(scope.row.level)+'级'"
              ></el-tag>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      authorityList: []
    }
  },

  created() {
    this.getAuthorityList()
  },

  methods: {
    // 获取权限列表
    getAuthorityList() {
      this.axios.get('rights/list').then(resp => {
        if (resp.meta.status !== 200) {
          return this.$message.error('获取权限列表失败！')
        }
        this.authorityList = resp.data
        this.$message.success('获取权限列表成功')
      })
    },
    // 显示权限等级
    displayLev(level, position) {
      let ret = ''
      if (position === 'type') {
        switch (level) {
          case '0':
            ret = 'primary'
            break
          case '1':
            ret = 'success'
            break
          case '2':
            ret = 'warning'
            break
          case '3':
            ret = 'info'
            break
          default:
            break
        }
        return ret
      }
      switch (level) {
        case '0':
          ret = '一'
          break
        case '1':
          ret = '二'
          break
        case '2':
          ret = '三'
          break
        case '3':
          ret = '四'
          break
        default:
          break
      }
      return ret
    }
  },

  components: {}
}
</script>

<style lang='scss' scoped>
</style>
